﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Lead2012.Utility;

namespace Lead2012.Business
{
    public class LeadCalendarItemRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();

        public List<CalendarInfoEx> GetAllCalendarBy(int userId, DateTime startDate)
        {
            List<CalendarInfoEx> list = new List<CalendarInfoEx>();
            DateTime startTime = LeadTools.StartOfDay(startDate);
            DateTime endTime = LeadTools.EndOfDay(startDate);

            var items = (from c in entities.CalendarItems
                         where c.UserId == userId && c.StartDate >= startTime && c.StartDate <= endTime
                         select new
                         {
                             LeadId = c.LeadId,
                             Title = c.Title,
                             StartDate = c.StartDate
                         }).ToList();

            foreach (var item in items)
            {
                CalendarInfoEx model = new CalendarInfoEx();
                model.Id = (item.LeadId == null) ? 0 : int.Parse(item.LeadId.ToString());
                model.LeadName = "Need auto";
                model.StartDate = item.StartDate;
                model.Title = item.Title;
                list.Add(model);
            }

            return list;
        }
    }
}